<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<head>
    <title>社交平台</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
</head>
<jsp:include page="/views/header.jsp"/>

<div class="container mt-4">
    <div class="row">
        <div class="col-md-3">
            <div class="card">
                <div class="card-header">
                    <h5>好友管理</h5>
                </div>
                <div class="card-body">
                    <ul class="nav flex-column">
                        <li class="nav-item">
                            <a class="nav-link active" href="${pageContext.request.contextPath}/friend/list">好友列表</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="${pageContext.request.contextPath}/friend/requests">好友请求</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="${pageContext.request.contextPath}/friend/search">查找好友</a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>


        <div class="col-md-9">
            <div class="card">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h5>好友列表</h5>
                    <span class="badge bg-primary">${friends.size()} 位好友</span>
                </div>
                <div class="card-body">
                    <c:if test="${not empty message}">
                        <div class="alert alert-success">${message}</div>
                    </c:if>
                    <c:if test="${not empty error}">
                        <div class="alert alert-danger">${error}</div>
                    </c:if>

                    <%-- 移除错误的好友请求显示部分 --%>

                    <c:if test="${empty friends}">
                        <div class="alert alert-info">您还没有好友，快去<a href="${pageContext.request.contextPath}/friend/search">添加好友</a>吧！</div>
                    </c:if>

                    <div class="row">
                        <c:forEach items="${friends}" var="friend">
                            <div class="col-md-4 mb-3">
                                <div class="card h-100">
                                    <div class="card-body text-center">
                                        <img src="${pageContext.request.contextPath}${not empty friend.avatar ? friend.avatar : '/images/default-avatar.png'}"
                                             class="friend-avatar-32" alt="好友头像">
                                        <h5 class="card-title">${friend.nickname}</h5>
                                        <p class="card-text text-muted">${friend.gender} · ${friend.age}岁</p>
                                        <div class="d-flex justify-content-center">
                                            <a href="${pageContext.request.contextPath}/post/list?userId=${friend.userId}"
                                               class="btn btn-sm btn-outline-primary me-2">查看日志</a>
                                            <form action="${pageContext.request.contextPath}/friend/remove" method="post" class="d-inline">
                                                <input type="hidden" name="friendId" value="${friend.userId}">
                                                <button type="submit" class="btn btn-sm btn-outline-danger">删除</button>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </c:forEach>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>


<jsp:include page="/views/footer.jsp"/>